package com.my.study.io.output;

import com.my.study.io.SteamCloseUtils;
import lombok.extern.slf4j.Slf4j;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * @author Carlos
 * @version 1.0
 * @Description 文件输出流
 *
 * 如果追加字符，使用构造方法FileOutputStream(File file, boolean append)
 * append = true;
 *
 * @date 2021/6/26 9:41
 **/
@Slf4j(topic = "c.FileOutputStreamTest")
public class FileOutputStreamTest {

    public static void main(String[] args) {
        String path = "D:/file/a.txt";
        test01(path);
    }

    private static void test01(String path) {
        FileOutputStream fos = null;
//        byte[] buf = new byte[8];
        try {
            fos = new FileOutputStream(path);
            String context = "Hello, World!";
            fos.write(context.getBytes());
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            SteamCloseUtils.close(fos, () -> "");
        }


    }

}
